package com.yfqy.app.domain.mapper;

import com.yfqy.app.domain.entity.Customer;
import org.apache.ibatis.annotations.Param;

public interface CustomerMapper {

    int insert(Customer record);

    Customer selectByPrimaryKey(Long id);

    Customer selectOneByPhone(@Param("phone") String phone);

    int getCustomerCurrentPoints(@Param("userId") long userId);

    Customer selectOneByOpenId(@Param("openId") String openid);

    Integer selectPointsByUserId(Long userId);

    int deductUserPoints(@Param("userId") Long userId, @Param("points") int points);

    int addUserPoints(@Param("userId") Long userId, @Param("points") int points);

    void updateById(@Param("customer") Customer customer);

    int updateAvatarNickname(@Param("nickname") String nickname, @Param("avatar") String avatar, @Param("userId") Long userId);

    int updatePhoneNumber(@Param("phoneNumber") String phoneNumber, @Param("id") Long userId);

    /**
     * CAS方式更新用户积分
     * @param userId 用户ID
     * @param newPoints 新的积分值
     * @param expectedCurrentPoints 预期的当前积分值（用于比较）
     * @return 更新影响的行数
     */
    int updateUserPointsCAS(@Param("userId") Long userId,
                            @Param("newPoints") Integer newPoints,
                            @Param("expectedCurrentPoints") Integer expectedCurrentPoints);
}